home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
rng.exe
/
RANDOM-C.DOC
< prev
next >
Wrap
Text File
|
1990-05-28
|
4KB
|
85 lines
Notes on the C Language Version
The C code was derived from PD1:<MSDOS.FORTRAN>RANDOM.ARC, and has
been linted with PC-Lint version 4.00a and tested using Microsoft C
version 5.10. In doing the translation, I tried to change as little
as possible; in fact, all of the variable names and function
(subroutine) names are the same in the C and FORTRAN versions. Some
of the comment blocks from the FORTRAN version were copied verbatim
into the C version.
The C language version as distributed will compile and execute as a
stand-alone program, allowing you to verify that the random number
generator is working correctly with your compiler (if your compiler
does not support full ANSI function prototypes, minor changes may be
required). When executed, the program should display the following
(after a delay of several seconds or more):
6533892.0 14220222.0 7275067.0 6172232.0 8354498.0 10633180.0
Use function main() as an example of how to call the random number
generator from your program.
The remainder of this file was copied from RANDOM.DOC from
PD1:<MSDOS.FORTRAN>RANDOM.ARC. Thanks to David LaSalle for posting it.
Jim Butler
Ithaca College
BUTLER%ITHACA.BITNET@CORNELLC.CIT.CORNELL.EDU
-------------------------------------------------------------------------
Date: Tue, 28 Feb 89 10:29:08 PST
From: MINUIT%FSU.MFENET@NMFECC.ARPA
Subject: á random number generators
When I posted the code for George Marsaglia's universal random number
generator, I forgot to mention that the seed variables can only have
certain values:
i, j, and k must be between 1 and 178 (not all of them 1)
l must be in the range 0 to 168
I am posting a slightly modified version of the code that requires only two
seed variables which basically have the range 0 to 30000. One nice feature
of this version is that each subsequence of numbers specified by the two
seeds has a length of approximately 10^30. If different parts of a large
calculation is being worked on by several people, each person could be
given his own IJ seed. That would leave 30000 more seeds for the individual
to use -- without fear that any part of the overall calculation would
experience correlations in the random numbers.
Finally, it should also be noted that to save the state of the random number
generator at any point in time, you have to save the entire contents of the
common block
- David LaSalle
minuit%fsu@nmfecc.arpa
SCRI
Florida State University
Tallahassee, FL 32306-4052
(904)644-1010
-------------------------------------------------------------------------
C This random number generator originally appeared in "Toward a Universal
C Random Number Generator" by George Marsaglia and Arif Zaman.
C Florida State University Report: FSU-SCRI-87-50 (1987)
C
C It was later modified by F. James and published in "A Review of Pseudo-
C random Number Generators"
C
C THIS IS THE BEST KNOWN RANDOM NUMBER GENERATOR AVAILABLE.
C (However, a newly discovered technique can yield
C a period of 10^600. But that is still in the development stage.)
C
C It passes ALL of the tests for random number generators and has a period
C of 2^144, is completely portable (gives bit identical results on all
C machines with at least 24-bit mantissas in the floating point
C representation).
C
C The algorithm is a combination of a Fibonacci sequence (with lags of 97
C and 33, and operation "subtraction plus one, modulo one") and an
C "arithmetic sequence" (using subtraction).
C
C On a Vax 11/780, this random number generator can produce a number in
C 13 microseconds (FORTRAN version - JB).
C========================================================================